import request from '@/utils/request'
import { encryptedData } from '@/utils/encrypt'
import { loginRSA, tokenName } from '@/config'

export async function login(data) {
  let remoteUrl = '/v1/ruizy/login/'
  if (loginRSA) {
    data = await encryptedData(data)
    remoteUrl = '/v1/ruizy/Login/'
  }
  return request({
    url: remoteUrl,
    method: 'post',
    data,
  })
}

export function getUserInfo(accessToken) {
  return request({
    url: '/v1/ruizy/userInfo/',
    method: 'post',
    data: {
      [tokenName]: accessToken,
    },
  })
}

export const RefreshToken = async () => {
  return request({
    url: '/v1/ruizy/refreshToken/',
    method: 'post',
  })
}

// 用户中心获取用户信息
export function userCenterInformation() {
  return request({
    url: '/v1/ruizy/userInfo/',
    method: 'get',
  })
}

// 用户个人中心修改资料
export function userCenterModifyInfo(data) {
  return request({
    url: '/v1/ruizy/userInfo/',
    method: 'put',
    data,
  })
}

// 新增证书奖项
export function createCertificatePrize(data) {
  return request({
    url: '/v1/ruizy/userInfo/certificatePrize/',
    method: 'post',
    data,
  })
}

// 删除证书奖项记录
export function delCertificatePrize(data) {
  return request({
    url: '/v1/ruizy/userInfo/certificatePrize/',
    method: 'delete',
    data,
  })
}

export function logout() {
  return request({
    url: '/v1/logout',
    method: 'post',
  })
}

export function register() {
  return request({
    url: '/v1/register',
    method: 'post',
  })
}

export function modifyPassword(data){
  return request({
    url: '/v1/ruizy/password/',
    method: 'post',
    data
  })
}

// 获取分析师列表
export function getAnalystList(){
  return request({
    url: '/v1/ruizy/user/analyst/',
    method: 'get'
  })
}
